package com.wuneng.ircontrol.myUtil.update;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.graphics.Point;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;

import com.wuneng.ircontrol.R;


/**
 * Created by ljm on 2018/1/11.
 * 升级提示框
 */

public class UpdateDialog extends Dialog {
    private Context context;
    private TextView updataversioncode, updataversion_msg;
    private CheckClickListener checkClickListener;


    public UpdateDialog(Context context, CheckClickListener checkClickListener) {
        super(context);
        this.context = context;
        this.checkClickListener = checkClickListener;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.setGravity(Gravity.CENTER);
        window.setWindowAnimations(R.style.AnimationPreview);
        setContentView(R.layout.dialog_updataversion);

//        updataversioncode = (TextView) findViewById(R.id.updataversioncode);
//        updataversioncode.setText(updateResBean.getOtainfo().getVersioncode());
//        updataversion_msg = (TextView) findViewById(R.id.updataversion_msg);
//        updataversion_msg.setText(updateResBean.getOtainfo().getUpdatemessage());
        window.setBackgroundDrawable(new ColorDrawable());//设置背景透明
        WindowManager windowManager = ((Activity) context).getWindowManager();
        Display display = windowManager.getDefaultDisplay();
        WindowManager.LayoutParams lp = getWindow().getAttributes();

        Point size = new Point();
        display.getSize(size);
        lp.width = size.x * 4 / 5; // 设置dialog宽度为屏幕的4/5
        getWindow().setAttributes(lp);
        // 点击Dialog外部消失
        setCanceledOnTouchOutside(true);
        Button btnCheck = (Button) findViewById(R.id.btnCheck);
        btnCheck.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                checkClickListener.click();
            }
        });
    }


}
